﻿-- SETUP --
local maincolor = {80/255, 64/255, 77/255}		-- mainly used for healthbar
local sndcolor = {208/255, 172/255, 146/255}	-- font color, ...
local trdcolor = {220/255, 220/255, 220/255}	-- castbar, buff/debuff borders

local mediaFolder = "Interface\\AddOns\\oUF_viv5\\media\\"	-- don't touch this ...
local HPtex = mediaFolder.."dZ"					-- health bar texture
local PPtex = mediaFolder.."dZ"					-- power bar texture
local CBtex = mediaFolder.."d2P"					-- castbar texture
local Auratex = mediaFolder.."dBBorderH"		-- border texture for buffs/debuffs

local glowtex = "Interface\\AddOns\\oUF_viv5\\media\\glowTex"		-- HP border texture (also used for threat highlight) -- glowTex, glowTex2, glowTex3, glowTex4 (thin > thicker)
local glowtex2 = "Interface\\AddOns\\oUF_viv5\\media\\glowTex2"		-- PP border texture (also used for debuff highlight) -- glowTex, glowTex2, glowTex3, glowTex4 (thin > thicker) 
	
local NameFont = mediaFolder.."BigNoodleTitling.ttf"	
local NumbFont = mediaFolder.."Prototype.ttf"	
local NameFS = 12
local NumbFS = 12 
local FontF = "THINOUTLINE" --local fontF = nil

local myDebuffSize = 32
local myBuffsize = 32

local useCBFT = false 				-- oUF Combat Feedback support
local useplayerauras = true 		-- show/hide playerauras (replace blizzards auras)
local FilterDebuffs = false			-- filter focus and target's auras to only show auras applied by the player (true)
local useIconGlow = true			-- show glow around buffs and debuffs

local useCastbar = true				-- show/hide player, target, focus castbar
local useSpellIcon = true			-- show/hide castbar spellicon
local useCastTime = false			-- show/hide casttime (requires useSpellIcon = true)
local useDKrunes = true				-- show/hide DeathKnight runes

local usemaintank = true			-- show/hide maintank, maintank target
local useArenaFrames = true			-- show/hide arena frames
local usebossframes = true			-- show/hide boss frames

local Numberzzz = 1					-- 0 will display 18400k as 18k, 1 = 18.4k, ....

-- scale some frames
local PlayerScale = 1.0		-- player, player pet
local TargetScale = 1.0		-- target, ToT
local FocusScale = 1.0		-- focus, focus target
local ArenaScale = 1.0		-- arena, arena ToT
local MainTankScale = 1.0	-- MT, MTT, (MTTT), boss frames

-- weapon enchant's position
local WeapEnchantAnchor = "TOPRIGHT"
local WeapEnchant_X = -60
local WeapEnchant_Y = -2

-- viewport settings --
local useviewport = false	-- show/hide viewport

-- set the scale of the texture panel overlaying the viewport - 1.0 = 1680x1050 @ UI scale of 1.0 (aka no UI scale)
-- this is for people using an UI scale and/or having a different resolution than 1680x1050 to make viewport textures fit
local panelscale = 1.0

-- set viewport height value for top and bottom
local viewportTopValue = 44		
local viewportBOTTOMValue = 44 	

-- set texture height value for top and bottom panel
local viewportTextureTopValue = 36		
local viewportTextureBottomValue = 36

-- change viewport textures
local BottomPanelTex = mediaFolder.."dO"
local TopPanelTex = mediaFolder.."dO"

local BottomPanelOvTex = mediaFolder.."dQ"		
local TopPanelOvTex = mediaFolder.."dQ"	

-- END OF CONFIG --

-- initial frame size
local height = {
		["L"] = 32,		-- player, target, focus
		["M"] = 18, 	-- arena, MT, ...
		["S"] = 18, 	-- ToT, FocusTarget, pet
		} 

local width = {
		["L"] = 230,	-- player, target, focus
		["M"] = 128, 	-- arena, MT, ...
		["S"] = 112, 	-- ToT, FocusTarget, pet
		}

-- menu
local menu = function(self)
	local unit = self.unit:sub(1, -2)
	local cunit = self.unit:gsub("(.)", string.upper, 1)

	if(unit == "party" or unit == "partypet") then
		ToggleDropDownMenu(1, nil, _G["PartyMemberFrame"..self.id.."DropDown"], "cursor", 0, 0)
	elseif(_G[cunit.."FrameDropDown"]) then
		ToggleDropDownMenu(1, nil, _G[cunit.."FrameDropDown"], "cursor", 0, 0)
	end
end

local playerClass = select(2, UnitClass("player"))	

-- format numbers
function round(num, idp)
  if idp and idp>0 then
    local mult = 10^idp
    return math.floor(num * mult + 0.5) / mult
  end
  return math.floor(num + 0.5)
end

function CoolNumber(num)
	if(num >= 1e6) then
		return round(num/1e6,Numberzzz).."m"
	elseif(num >= 1e3) then
		return round(num/1e3,Numberzzz).."k"
	else
		return num
	end
end

-- hp pp update func
local updateHealth = function(self, event, unit, bar, min, max)
    local d =(round(min/max, 2)*100)
	if(UnitIsDead(unit)) then
		bar:SetValue(0)
		bar.value:SetText"RIP"		
		bar.PERvalue:SetText(" ")
	elseif(UnitIsGhost(unit)) then
		bar:SetValue(0)
		bar.value:SetText"GHO"		
		bar.PERvalue:SetText(" ")
	elseif(not UnitIsConnected(unit)) then
		bar.value:SetText"OFF"	
		bar.PERvalue:SetText(" ")
	elseif(UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) then
		bar.value:SetText(CoolNumber(min))	
		bar.PERvalue:SetText("TAPPED")
	elseif(unit == "player") then
		if(d < 100) then
			bar.PERvalue:SetText((round(min/max, 2)*100))
			bar.PERvalue:Show()			
			bar.value:SetText(CoolNumber(min))
		else
			bar.PERvalue:SetText(" ")
			bar.PERvalue:Hide()	
			bar.value:SetText(CoolNumber(min))
		end	
	elseif(unit == "target")or(unit == "focus") then
		if(d < 100) then
		bar.PERvalue:SetText((round(min/max, 2)*100))
		bar.PERvalue:Show()
		else
		bar.PERvalue:Hide()	
		end
		bar.value:SetText(CoolNumber(min))
	else
		bar.value:SetText(CoolNumber(min))
	end
	
	bar.value:SetTextColor(sndcolor[1], sndcolor[2], sndcolor[3])
	bar.PERvalue:SetTextColor(sndcolor[1], sndcolor[2], sndcolor[3])
	--bar.value:SetTextColor(maincolor[1],maincolor[2],maincolor[3])
	--bar.PERvalue:SetTextColor(maincolor[1],maincolor[2],maincolor[3])
end

local updatePower = function(self, event, unit, bar, min, max)
	local dp =(round(min/max, 2)*100)
	if(min == 0 or max == 0 or not UnitIsConnected(unit)) then
		bar.value:SetText()
		bar:SetValue(0)
	elseif(UnitIsDead(unit) or UnitIsGhost(unit)) then
		bar:SetValue(0)
	elseif(unit == "player") then
		if(dp < 100) then
			bar.value:Show()
			bar.value:SetText(CoolNumber(min))
		else
			bar.value:Hide()
		end	
	elseif(unit == "target")or(unit == "focus") then
		bar.value:SetText(CoolNumber(min))
	else
		bar.value:SetText(CoolNumber(min))
	end
	
	bar.value:SetTextColor(sndcolor[1], sndcolor[2], sndcolor[3])
	--bar.value:SetTextColor(maincolor[1],maincolor[2],maincolor[3])
	
	-- hide target's power bar for npcs without power
	if unit=="target" then
			if ( UnitIsPlayer("target") ) then
			self.Power:Show()
			self.Glow.pp:Show()
			else
			if ( UnitPowerType("target") ~= 0 ) then
				self.Power:Hide()
				self.Glow.pp:Hide()
			end
		end
	end		
end

-- druid mana
oUF.TagEvents['[druidpower]'] = 'UNIT_MANA UPDATE_SHAPESHIFT_FORM'
oUF.Tags['[druidpower]'] = function(unit)
	local min, max = UnitPower(unit, 0), UnitPowerMax(unit, 0)
	return UnitPowerType(unit) ~= 0 and format('|cfdcdcdcf%d - %d%%|r', min, math.floor(min / max * 100))
end

local function updateDruidPower(self, event, unit)
	if(unit and unit ~= self.unit) then return end

	local mana = UnitPowerType('player') == 0
	local min, max = UnitPower('player', mana and 3 or 0), UnitPowerMax('player', mana and 3 or 0)

end

-- custom tags
oUF.Tags['[afkdnd]'] = function(unit)
	if unit then
		return UnitIsAFK(unit) and '|cffffffff<AFK>|r ' or UnitIsDND(unit) and '|cffffffff<DND>|r '
	end
end
oUF.TagEvents['[afkdnd]'] = 'PLAYER_FLAGS_CHANGED'

oUF.Tags['[abbrev]'] = function(unit)
	local len
	if(unit == "target")or(unit == "focus") then
		len = 14
	else
		len = 10
	end
	local name = UnitName(unit)
	return string.len(name) > len and string.gsub(name, '%s?(.)%S+%s', '%1. ') or name
end

oUF.Tags['[abbrevname]'] = function(unit)
	if not UnitIsPlayer(unit) then
		return oUF.Tags['[abbrev]'](unit)
	else
		return oUF.Tags['[name]'](unit)
	end
end
oUF.TagEvents['[abbrevname]'] = 'UNIT_NAME_UPDATE'

local utf8sub = function(string, i, dots)
	local bytes = string:len()
	if (bytes <= i) then
		return string
	else
		local len, pos = 0, 1
		while(pos <= bytes) do
			len = len + 1
			local c = string:byte(pos)
			if (c > 0 and c <= 127) then
				pos = pos + 1
			elseif (c >= 192 and c <= 223) then
				pos = pos + 2
			elseif (c >= 224 and c <= 239) then
				pos = pos + 3
			elseif (c >= 240 and c <= 247) then
				pos = pos + 4
			end
			if (len == i) then break end
		end

		if (len == i and pos <= bytes) then
			return string:sub(1, pos - 1)..(dots and '...' or '')
		else
			return string
		end
	end
end

if (not oUF.Tags['[shortname]']) then
	oUF.Tags['[shortname]'] = function(unit)
		local name = UnitName(unit)
		return utf8sub(name, 6, false)
	end
end
oUF.TagEvents['[shortname]'] = 'UNIT_NAME_UPDATE'

oUF.Tags["[raidhpname]"] = function(u)
local name = UnitName(u)
local c, m = UnitHealth(u), UnitHealthMax(u) 
if c == 0 then return "RIP" elseif(UnitIsGhost(u)) then return "GHO" elseif(not UnitIsConnected(u)) then return "OFF" elseif c < m then return oUF.Tags["[missinghp]"](u) else return utf8sub(name, 6, false) end end
oUF.TagEvents["[raidhpname]"] = "UNIT_HEALTH UNIT_MAXHEALTH UNIT_NAME_UPDATE"
	
-- skinning buffs and aura functions
local function auraIcon(self, icon, icons, index, debuff)
		icons.showDebuffType = true		-- show debuff border type color 
		icon.cd.noOCC = true		 	-- hide OmniCC CDs
		icon.cd.noCooldownCount = true	-- hide CDC CDs
		icons.disableCooldown = true	-- hide CD spiral
	
		icon.count:SetFont(NumbFont, NumbFS*0.8, FontF)
		icon.count:SetPoint("TOPRIGHT", icon, 4, 22)
	
		icon.time = icon:CreateFontString(nil, 'OVERLAY')
		icon.time:SetFont(NumbFont, NumbFS*0.84, FontF)
		icon.time:SetPoint('TOP', icon, 'BOTTOM', 0, 10)
		icon.time:SetJustifyH('CENTER')
		icon.time:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])
		
		icon.icon:SetTexCoord(.07, .93, .07, .93)
		icon.icon:SetPoint("TOPLEFT", icon, "TOPLEFT", 2, -2)
		icon.icon:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", -2, 2)
		
		if useIconGlow == true then		
		icon.Glow = CreateFrame("Frame", nil, icon)
		icon.Glow:SetPoint("TOPLEFT", icon, "TOPLEFT", -4, 4)
		icon.Glow:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", 4, -4)
		icon.Glow:SetFrameStrata("BACKGROUND")	
		icon.Glow:SetBackdrop{edgeFile = glowtex, edgeSize = 5, insets = {left = 4, right = 4, top = 4, bottom = 4}}
		icon.Glow:SetBackdropColor(0, 0, 0, 0)
		icon.Glow:SetBackdropBorderColor(0, 0, 0)
		self.Glow:SetFrameStrata("BACKGROUND")		
		end
		
		icon.overlay:SetTexture(Auratex)
		icon.overlay:SetTexCoord(0,1,0,1)
		icon.overlay.Hide = function(self) self:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3]) end
		--icon.overlay.Hide = function(self) self:SetVertexColor(sndcolor[1], sndcolor[2], sndcolor[3]) end
		--icon.overlay.Hide = function(self) self:SetVertexColor(maincolor[1],maincolor[2],maincolor[3]) end	

end

local function WeapEnchantIcon(self, icon, icons)
	icon.icon:SetTexCoord(.07, .93, .07, .93)
	icon.icon:SetPoint("TOPLEFT", icon, "TOPLEFT", 2, -2)
	icon.icon:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", -2, 2)
		
	icon.overlay:SetTexture(Auratex)
	icon.overlay:SetTexCoord(0, 1, .01, 1)
	--icon.overlay:SetVertexColor(maincolor[1],maincolor[2],maincolor[3])
	icon.overlay:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])
end


-- duration text
local function auraUpdateTimeShort(self, elapsed)
	self.timeLeft = math.max(self.timeLeft - elapsed, 0)
	self.time:SetText(self.timeLeft < 120 and math.floor(self.timeLeft) or '')
end

local function auraUpdateIcon(self, icons, unit, icon, index, offset, filter, isDebuff, duration, timeLeft)
    if(unit == "target")or(unit == "focus") then
		local _, _, _, _, dtype = UnitAura(unit, index, icon.filter)

		if(icon.debuff) then
			icons.showDebuffType = false		
			if(icon.owner ~= 'player' and icon.owner ~= 'vehicle' and icon.owner ~= 'pet') then
			icon:SetBackdropColor(0, 0, 0)
			icon.overlay:SetVertexColor(maincolor[1], maincolor[2], maincolor[3])			
			icon.icon:SetDesaturated(true)
			else
			local color = DebuffTypeColor[dtype] or DebuffTypeColor.none
			icon:SetBackdropColor(color.r * 0.9, color.g * 0.9, color.b * 0.9)
			icon.overlay:SetVertexColor(color.r * 0.9, color.g * 0.9, color.b * 0.9)			
			icon.icon:SetDesaturated(false)
			end
		end	
	end

	if(unit) then 
			local _, _, _, _, _, duration, timeLeft = UnitAura(unit, index, filter)

		icon.timeLeft = timeLeft - GetTime()			
		icon:SetScript('OnUpdate', auraUpdateTimeShort)	

		if duration == 0 or not timeLeft then
			icon.timeLeft = nil
			icon.time:SetText()
			icon:SetScript('OnUpdate', nil)
		end		
	end

	if(self:GetName():match"oUF_Arena") then 	
		icon.count:SetFont(NumbFont, NumbFS*0.6, FontF)
		icon.count:SetPoint("TOPRIGHT", icon, 4, 14)
		icon.time:SetFont(NumbFont, NumbFS*0.68, FontF)
		icon.time:SetPoint('TOP', icon, 'BOTTOM', 0, 6)		
	end
end

-- update combo point func
local function updateCPoints(self, event, unit)
	if unit == PlayerFrame.unit and unit ~= self.CPoints.unit then
		self.CPoints.unit = unit
	end
end

-- threat highlight
local function updateThreatStatus(self, event, u)
	if (self.unit ~= u) then return end
	local s = UnitThreatSituation(u)
	if s and s > 1 then
		local r, g, b = GetThreatStatusColor(s)
		self.Glow:SetBackdropBorderColor(r, g, b, 1)
	else
		self.Glow:SetBackdropBorderColor(0, 0, 0, 1)
	end
end

-- debuff highlight
local CanDispel = {
	PRIEST = { Magic = true, Disease = true, },
	SHAMAN = { Poison = true, Disease = true, },
	PALADIN = { Magic = true, Poison = true, Disease = true, },
	MAGE = { Curse = true, },
	DRUID = { Curse = true, Poison = true, }
}
local dispellist = CanDispel[playerClass] or {}

local function GetDebuffType(unit)
	if not UnitCanAssist("player", unit) then return nil end
	local i = 1
	while true do
		local name, rank, texture, count, debufftype, duration, expirationTime, source = UnitDebuff(unit, i)
		if not texture then break end
		if debufftype and dispellist[debufftype] then
			return debufftype
		end
		i = i + 1
	end
end

local function updateDispel(self, event, u)
	if not u or self.unit ~= u then return end
	local debufftype = GetDebuffType(u)
	if debufftype then
		local color = DebuffTypeColor[debufftype] 
		self.Glow.pp:SetBackdropBorderColor(color.r, color.g, color.b, 0.8)
	else
		self.Glow.pp:SetBackdropBorderColor(0, 0, 0, 0.8)
	end
end

local function castGlow(self, event, unit, interrupt)
	local cb = self.Castbar
	if(cb.interrupt) then
		self.Glow.cbIcon:SetBackdropBorderColor(125/255, 255/255, 255/255, 0.8)	
	else
		self.Glow.cbIcon:SetBackdropBorderColor(0, 0, 0, 0.8)	
	end
end

-- layout
local Shared = function(self, unit)
	self.menu = menu

	self:SetScript("OnEnter", UnitFrame_OnEnter)
	self:SetScript("OnLeave", UnitFrame_OnLeave)

	self:RegisterForClicks"anyup"
	self:SetAttribute("*type2", "menu")

	-- disable pet castbar
	PetCastingBarFrame:UnregisterAllEvents()
	PetCastingBarFrame.Show = function() end
	PetCastingBarFrame:Hide()
	
	-- hp
	local hp = CreateFrame("StatusBar", nil, self)
	hp:SetHeight(height.L)
	hp:SetWidth(width.L*0.7)	
	hp:SetStatusBarTexture(HPtex)	
	hp:SetPoint("LEFT", self, "LEFT", 0, 0)	
	hp:SetStatusBarColor(maincolor[1],maincolor[2],maincolor[3])	
	hp:SetAlpha(0.8)	
	hp.frequentUpdates = true
	self.Health = hp	

	hp.bg = hp:CreateTexture(nil, "BORDER")
	hp.bg:SetAllPoints(hp)
	hp.bg:SetTexture(HPtex)
	hp.bg:SetAlpha(0.4)
	hp.bg:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])
	
	self.Glow = CreateFrame("Frame", nil, self)
	self.Glow:SetPoint("TOPLEFT", self, "TOPLEFT", -5, 5)
	self.Glow:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", 5, -5)
	self.Glow:SetBackdrop{edgeFile = glowtex, edgeSize = 5, insets = {left = 3, right = 3, top = 3, bottom = 3}}
	self.Glow:SetBackdropColor(0, 0, 0, 0)
	self.Glow:SetBackdropBorderColor(0, 0, 0, 1)	

	-- pp	
	local pp = CreateFrame("StatusBar", nil, self)
	pp:SetHeight(6)
	pp:SetWidth(width.L*0.44)
	pp:SetStatusBarTexture(PPtex)
	pp:SetPoint("BOTTOMRIGHT", hp, "BOTTOMRIGHT", -2, 0)	
	pp:SetAlpha(0.8)
	pp:SetFrameLevel(14)
	
	pp.frequentUpdates = true
	pp.colorTapping = true
	pp.colorHappiness = true
	pp.colorClass = true
	--pp.colorClassNPC = true	
	pp.colorReaction = true
	self.Power = pp	
	
	pp.bg = pp:CreateTexture(nil, "BORDER")
	pp.bg:SetAllPoints(pp)
	pp.bg:SetTexture(PPtex)
	pp.bg:SetAlpha(0.4)
	pp.bg:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])	
	
	self.Glow.pp = CreateFrame("Frame", nil, pp)
	self.Glow.pp:SetPoint("TOPLEFT", pp, "TOPLEFT", -5, 5)
	self.Glow.pp:SetPoint("BOTTOMRIGHT", pp, "BOTTOMRIGHT", 5, -5)
	self.Glow.pp:SetBackdrop{edgeFile = glowtex2, edgeSize = 5, insets = {left = 3, right = 3, top = 3, bottom = 3}}
	self.Glow.pp:SetBackdropColor(0, 0, 0, 0.8)
	self.Glow.pp:SetBackdropBorderColor(0, 0, 0)	
	
	-- player, target, focus portraits	
	if unit=="player" or unit=="target" or unit=="focus" then	
		local portrait = CreateFrame("PlayerModel", nil, self)
		portrait:SetHeight(height.L)
		portrait:SetWidth(width.L*0.3)
		portrait:SetPoint("TOPLEFT", hp, "TOPRIGHT", 0, 0)
		self.Portrait = portrait
		portrait:SetAlpha(0.8)
		
		portrait.bg = CreateFrame("Frame", nil, self)
		portrait.bg:SetPoint("TOPLEFT", portrait, "TOPLEFT", -0, 0)
		portrait.bg:SetPoint("BOTTOMRIGHT", portrait, "BOTTOMRIGHT", 0, -0)
		portrait.bg:SetBackdrop{bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=], insets = {top = -1, bottom = -1, left = -1, right = -1}}
		portrait.bg:SetBackdropColor(0, 0, 0, 0.7)
		portrait.bg:SetBackdropBorderColor(0, 0, 0)
	end
	
	local HidePortrait = function(self, unit) -- attempt to hide portraits when not available
		if (not UnitExists(self.unit) or not UnitIsConnected(self.unit) or not UnitIsVisible(self.unit)) then
			self.Portrait:SetAlpha(0)
		else
			self.Portrait:SetAlpha(0.8)
		end
	end	
	
	-- font strings
	hp.value = hp:CreateFontString(nil, "ARTWORK")
	hp.value:SetFont(NumbFont, NumbFS*1.8, FontF)
	
	hp.PERvalue = hp:CreateFontString(nil, "ARTWORK")
	hp.PERvalue:SetFont(NumbFont, NumbFS, FontF)
	
	pp.value = pp:CreateFontString(nil, "ARTWORK")
	pp.value:SetFont(NumbFont, NumbFS, FontF)
	
	self.Name = hp:CreateFontString(nil, "ARTWORK")
	self.Name:SetFont(NameFont, NameFS, FontF)
	self:Tag(self.Name, '[afkdnd][raidcolor][abbrevname]')
	
	self.Text = hp:CreateFontString(nil, "ARTWORK")
	self.Text:SetFont(NameFont, NameFS, FontF)
	self.Text:SetTextColor(sndcolor[1], sndcolor[2], sndcolor[3])	
	self:Tag(self.Text, '[status]')

	-- plugin support
	if IsAddOnLoaded("oUF_CombatFeedback") and useCBFT == true then
		local cbft = hp:CreateFontString(nil, "ARTWORK")
		cbft:SetPoint("CENTER", hp, "CENTER", 0, 0)
		cbft:SetFontObject(GameFontNormal)
		self.CombatFeedbackText = cbft	
		self.CombatFeedbackText:SetFont(NumbFont, NumbFS*0.8, FontF)
		
		-- hide combat feedback on player pet
		if unit=="pet" then		
		self.CombatFeedbackText.ignoreImmune = true -- ignore 'immune' reports
		self.CombatFeedbackText.ignoreDamage = true -- ignore damage hits, blocks, misses, parries etc.
		self.CombatFeedbackText.ignoreHeal = true -- ignore heals 		
		self.CombatFeedbackText.ignoreEnergize = true -- ignore energize events
		self.CombatFeedbackText.ignoreOther = true  -- ignore everything else
		end
	end

	if IsAddOnLoaded("oUF_SpellRange") then	
		if(unit) then 
		self.SpellRange = true; -- fadeout if units are out of range
		self.inRangeAlpha = 1.0; -- Frame alpha when in range
		self.outsideRangeAlpha = 0.3; -- Frame alpha when out of range
		end	
	end

	if IsAddOnLoaded("oUF_Smooth") then	
		if(unit) then 
		hp.Smooth = true
		pp.Smooth = true	
		end	
	end	

	if IsAddOnLoaded("oUF_BarFader") then		
		if(unit == "player") or (unit == "pet") then
		self.BarFade = true
		self.BarFaderMinAlpha = 0	
		end
	end
	
	if IsAddOnLoaded("oUF_HealComm4") then			
	HCB = CreateFrame('StatusBar', nil, hp)
	HCB:SetStatusBarTexture(HPtex)
	HCB:SetStatusBarColor(0, 0.8, 0, 0.4)
	HCB:SetPoint('LEFT', hp, 'LEFT')
	self.HealCommBar = HCB
	self.allowHealCommOverflow = false
	self.HealCommOthersOnly = true
	end
	
	-- raid icons
	RI = hp:CreateTexture(nil, "OVERLAY")
	RI:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons")
	RI:SetHeight(16)
	RI:SetWidth(16)
    RI:SetPoint("LEFT", hp, "RIGHT", -8, 6)	
	self.RaidIcon = RI
	
	-- castbar fluff
	if useCastbar == true then	
	if(unit == "player") or (unit=="target") or (unit == "focus") or (unit == "pet") then
	local cb = CreateFrame("StatusBar", nil, self)
	cb:SetStatusBarTexture(CBtex)
	cb:SetStatusBarColor(sndcolor[1], sndcolor[2], sndcolor[3], 0.8)
	cb:SetAllPoints(pp)
	cb:SetToplevel(true)
	self.Castbar = cb
	
	cb.Text = cb:CreateFontString(nil, 'ARTWORK')
	cb.Text:SetPoint("TOPLEFT", hp, "TOPLEFT", 34,0)
	cb.Text:SetPoint("BOTTOMRIGHT", hp, "BOTTOMRIGHT", 0,6)
	cb.Text:SetFont(NumbFont, NumbFS*0.75, FontF)
	cb.Text:SetTextColor(sndcolor[1], sndcolor[2], sndcolor[3]) 

	cb.Spark = cb:CreateTexture(nil, 'OVERLAY')
	cb.Spark:SetHeight(18)
	cb.Spark:SetWidth(8)
	cb.Spark:SetVertexColor(1, 1 , 1)
	cb.Spark:SetBlendMode('ADD')
		
		if(unit == "player") then
		cb.SafeZone = cb:CreateTexture(nil,"ARTWORK")
		cb.SafeZone:SetTexture(CBtex)
		cb.SafeZone:SetVertexColor(0.85,0.10,0.10,0.90)
		cb.SafeZone:SetPoint("TOPRIGHT")
		cb.SafeZone:SetPoint("BOTTOMRIGHT")	
		end
	
		if useSpellIcon == true then 	
		cb.Icon = cb:CreateTexture(nil, 'BACKGROUND')
		cb.Icon:SetHeight(height.L-2)
		cb.Icon:SetWidth(height.L-2)
		cb.Icon:SetTexCoord(0.1,0.9,0.1,1)
		if(unit == "player" or unit == "focus" or unit == "pet") then
			cb.Icon:SetPoint("LEFT", self, "RIGHT", 6, 0)
			else
			cb.Icon:SetPoint("RIGHT", self, "LEFT", -6, 0)
		end
		
		self.Glow.cbIcon = CreateFrame("Frame", nil, cb)
		self.Glow.cbIcon:SetPoint("TOPLEFT", cb.Icon, "TOPLEFT", -9, 9)
		self.Glow.cbIcon:SetPoint("BOTTOMRIGHT", cb.Icon, "BOTTOMRIGHT", 9, -9)
		self.Glow.cbIcon:SetBackdrop{edgeFile = glowtex, edgeSize = 9, insets = {left = 5, right = 5, top = 5, bottom = 5}}
		self.Glow.cbIcon:SetBackdropColor(0, 0, 0)
		self.Glow.cbIcon:SetBackdropBorderColor(0, 0, 0, 0.8)
		self.Glow.cbIcon:SetFrameStrata("BACKGROUND")
		
		cb.Icon.bg = cb:CreateTexture(nil, "OVERLAY")
		cb.Icon.bg:SetAllPoints(cb.Icon)
		cb.Icon.bg:SetPoint("TOPLEFT", cb.Icon, "TOPLEFT", -2, 2)
		cb.Icon.bg:SetPoint("BOTTOMRIGHT", cb.Icon, "BOTTOMRIGHT", 2, -2)		
		cb.Icon.bg:SetTexture(Auratex)
		cb.Icon.bg:SetAlpha(1)
		cb.Icon.bg:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])
		--cb.Icon.bg:SetVertexColor(maincolor[1], maincolor[2], maincolor[3])
		
		self.PostCastStart = castGlow
		self.PostChannelStart = castGlow
		end
		
		if useCastTime == true and useSpellIcon == true then		
		cb.Time = cb:CreateFontString(nil, 'ARTWORK')
		cb.Time:SetPoint("TOPLEFT", cb.Icon, "TOPLEFT", -2, 2)
		cb.Time:SetPoint("BOTTOMRIGHT", cb.Icon, "BOTTOMRIGHT", 2, -2)		
		cb.Time:SetFont(NumbFont, NumbFS*0.7, FontF)
		cb.Time:SetTextColor(trdcolor[1], trdcolor[2], trdcolor[3])
		end
	end
	end

	if(unit == "player") or (unit=="target") or (unit == "focus") then	
	self:SetAttribute('initial-height', height.L)
	self:SetAttribute('initial-width', width.L)	
	end
	
	if(unit == "player") then
		hp.value:SetPoint("BOTTOMRIGHT", self, "TOPRIGHT", 0, 0)
		hp.PERvalue:SetPoint("TOPLEFT", hp, "TOPLEFT", 2, -2)		
		pp.value:SetPoint("BOTTOMLEFT", hp, "BOTTOMLEFT", 2, 2)
		
		if IsAddOnLoaded("oUF_WeaponEnchant") then
			self.Enchant = CreateFrame("Frame", nil, self)
			self.Enchant:SetHeight(32)
			self.Enchant:SetWidth(34 * 2)
			self.Enchant:SetPoint(WeapEnchantAnchor, UIParent, WeapEnchant_X, WeapEnchant_Y)
			self.Enchant.size = 32
			self.Enchant.spacing = 1
			self.Enchant.initialAnchor = "TOPLEFT"
			self.Enchant["growth-x"] = "RIGHT"
			self.PostCreateEnchantIcon = WeapEnchantIcon
		end
		
		if playerClass=="DRUID" then
			local value = pp:CreateFontString(nil, 'OVERLAY')
			value:SetPoint('CENTER', pp, 0, 0)			
			value:SetFont(NumbFont, NumbFS*0.8, FontF)		
			self:Tag(value, '[druidpower]')

			table.insert(self.__elements, updateDruidPower)
			self:RegisterEvent('UNIT_MANA', updateDruidPower)
			self:RegisterEvent('UNIT_ENERGY', updateDruidPower)
			self:RegisterEvent('UPDATE_SHAPESHIFT_FORM', updateDruidPower)
		end
		
		if IsAddOnLoaded("oUF_TotemBar") and playerClass == "SHAMAN" then
		self.TotemBar = {}
		for i = 1, 4 do
		self.TotemBar[i] = CreateFrame("StatusBar", nil, self)
		self.TotemBar[i]:SetHeight(6)
		self.TotemBar[i]:SetWidth(((width.L - 12) / 4)*0.66)
		if (i == 1) then
			self.TotemBar[i]:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 4)
		else
			self.TotemBar[i]:SetPoint("TOPLEFT", self.TotemBar[i-1], "TOPRIGHT", 4, 0)
		end
		self.TotemBar[i]:SetStatusBarTexture(HPtex)
		self.TotemBar[i]:SetMinMaxValues(0, 1)
		self.TotemBar[i].destroy = true
			
		self.TotemBar[i].bg = self.TotemBar[i]:CreateTexture(nil, "BORDER")
		self.TotemBar[i].bg:SetAllPoints(self.TotemBar[i])
		self.TotemBar[i].bg:SetTexture(HPtex)
		self.TotemBar[i].bg.multiplier = 0.4
		self.TotemBar[i].bg:SetAlpha(0.8)
			
		self.TotemBar[i].bg2 = self.TotemBar[i]:CreateTexture(nil, "BORDER")
		self.TotemBar[i].bg2:SetAllPoints(self.TotemBar[i])
		self.TotemBar[i].bg2:SetTexture(HPtex)
		self.TotemBar[i].bg2:SetAlpha(0.5)
		self.TotemBar[i].bg2:SetPoint("TOPLEFT", self.TotemBar[i], "TOPLEFT", -1, 1)
		self.TotemBar[i].bg2:SetPoint("BOTTOMRIGHT", self.TotemBar[i], "BOTTOMRIGHT", 1, -1)	
		self.TotemBar[i].bg2:SetVertexColor(0, 0, 0)
		end
		end
		
		if useDKrunes == true and playerClass =="DEATHKNIGHT" then		
			self.Runes = CreateFrame('Frame', nil, self)
			self.Runes:SetPoint('BOTTOMLEFT', self, 'TOPLEFT', 0, 4)
			self.Runes:SetHeight(6)
			self.Runes:SetWidth((width.L - 10)*0.68)
			self.Runes.anchor = 'TOPLEFT'
			self.Runes.growth = 'RIGHT'
			self.Runes.height = 6
			self.Runes.width = ((width.L - 10) / 6)*0.68
			self.Runes.spacing = 2

			for index = 1, 6 do
			self.Runes[index] = CreateFrame('StatusBar', nil, self.Runes)
			self.Runes[index]:SetStatusBarTexture(HPtex)

			self.Runes[index].bg = self.Runes[index]:CreateTexture(nil, "BORDER")
			self.Runes[index].bg:SetAllPoints(self.Runes[index])
			self.Runes[index].bg:SetTexture(HPtex)
			self.Runes[index].bg:SetAlpha(0.3)

			self.Runes[index].bg2 = self.Runes[index]:CreateTexture(nil, "BACKGROUND")
			self.Runes[index].bg2:SetAllPoints(self.Runes[index])
			self.Runes[index].bg2:SetTexture(HPtex)
			self.Runes[index].bg2:SetAlpha(0.5)
			self.Runes[index].bg2:SetVertexColor(0, 0, 0)
			self.Runes[index].bg2:SetPoint("TOPLEFT", self.Runes[index], "TOPLEFT", -1, 1)
			self.Runes[index].bg2:SetPoint("BOTTOMRIGHT", self.Runes[index], "BOTTOMRIGHT", 1, -1)				
			end
		else
			-- hide blizzard rune frame
			RuneFrame:Hide()
		end
	
		RIc = hp:CreateTexture(nil, 'OVERLAY')
		RIc:SetHeight(10)
		RIc:SetWidth(10)
		RIc:SetPoint("BOTTOMLEFT", hp, "TOPLEFT", width.L*0.2, -6)
		RIc:SetTexture(mediaFolder.."rest.tga")		
		RIc:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])		
		self.Resting = RIc
		
		CIc = hp:CreateTexture(nil, 'OVERLAY')
		CIc:SetHeight(10)
		CIc:SetWidth(10)
		CIc:SetPoint("LEFT", RIc, "RIGHT", 4, 0)	
		CIc:SetTexture(mediaFolder.."combat.tga")	
		CIc:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])		
		self.Combat = CIc			
		
		LIc = hp:CreateTexture(nil, "OVERLAY")
		LIc:SetHeight(10)
		LIc:SetWidth(10)
		LIc:SetPoint("LEFT", CIc, "RIGHT", 4, 0)
		LIc:SetTexture(mediaFolder.."leader.tga")
		LIc:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])			
		self.Leader = LIc
		
		MLIc = hp:CreateTexture(nil, 'OVERLAY')
		MLIc:SetHeight(10)
		MLIc:SetWidth(10)
		MLIc:SetPoint("LEFT", LIc, "RIGHT", 4, 0)
		MLIc:SetTexture(mediaFolder.."looter.tga")	
		MLIc:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])	
		self.MasterLooter = MLIc
		
	if useplayerauras == true then
	-- hide blizzard buff and weapon buff frame
	BuffFrame:Hide()
	TemporaryEnchantFrame:Hide()

		self.Auras = CreateFrame("Frame", nil, self)
		self.Auras.size = myDebuffSize	
		self.Auras:SetHeight((width.L/10)*2+6)
		self.Auras:SetWidth(width.L)
		self.Auras.spacing = 1
		self.Auras.numBuffs = 20
		self.Auras.numDebuffs = 40
		self.Auras.gap = true
		self.Auras:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 24)
		self.Auras.initialAnchor = "BOTTOMLEFT"
		self.Auras["growth-x"] = "RIGHT"		
		self.Auras["growth-y"] = "UP"
	end	
	end

    if(unit == "target")or(unit == "focus") then
	table.insert(self.__elements, HidePortrait)	

		self.Auras = CreateFrame("Frame", nil, self)
		self.Auras.size = myDebuffSize		
		self.Auras:SetHeight((width.L/10)*2+6)
		self.Auras:SetWidth(width.L)
		self.Auras.spacing = 1
		self.Auras.numBuffs = 20
		self.Auras.numDebuffs = 40
		self.Auras.gap = true
		self.Auras:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 24)
		self.Auras.initialAnchor = "BOTTOMLEFT"
		self.Auras["growth-x"] = "RIGHT"		
		self.Auras["growth-y"] = "UP"
		
	self.Name:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 2, 2)
	self:Tag(self.Name, '[difficulty][classification] [afkdnd][raidcolor][abbrevname]')
		
	hp.value:SetPoint("BOTTOMRIGHT", self, "TOPRIGHT", 0, 0)
	hp.PERvalue:SetPoint("TOPLEFT", hp, "TOPLEFT", 2, -2)		
	pp.value:SetPoint("BOTTOMLEFT", hp, "BOTTOMLEFT", 2, 2)
		
		if FilterDebuffs == true then
			self.Auras.onlyShowPlayer = true
		end		
	end

    if(unit == "target") then	
	if playerClass =="ROGUE" or playerClass =="DRUID" then
	self.Name:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 2, 12)
	
	local function comboPbackdrop(f)
		f:SetBackdrop( { 
		bgFile = HPtex, 
		edgeFile = "", tile = false, tileSize = 0, edgeSize = 32, 
		insets = { left = -1, right = -1, top = -1, bottom = -1 }
		})
		f:SetBackdropColor(0,0,0,0.6)
	end
	
	local function createComboPoints(self,unit)
		self.CPoints = {}
		self.CPoints.unit = "player"
    
		for i = 1, 5 do
		self.CPoints[i] = CreateFrame("Frame", nil, self)
		self.CPoints[i]:SetHeight(6)
		self.CPoints[i]:SetWidth(((width.L - 10) / 5)*0.5)
		comboPbackdrop(self.CPoints[i])
      
		self.CPoints[i].bg = self.CPoints[i]:CreateTexture(nil, "LOW")
		self.CPoints[i].bg:SetTexture(HPtex)
		self.CPoints[i].bg:SetAllPoints(self.CPoints[i])	
      
		if(i==1) then
			self.CPoints[i]:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 4)
		else
			self.CPoints[i]:SetPoint("TOPLEFT", self.CPoints[i-1], "TOPRIGHT", 2, 0)
		end
		end
		self.CPoints[1].bg:SetVertexColor(0,1,1)
		self.CPoints[2].bg:SetVertexColor(0,0.75,0.75)
		self.CPoints[3].bg:SetVertexColor(0.75,0.75,0)
		self.CPoints[4].bg:SetVertexColor(1,0.25,0)
		self.CPoints[5].bg:SetVertexColor(1,0,0)
		self:RegisterEvent("UNIT_COMBO_POINTS", updateCPoints)  
	end	
	
	createComboPoints(self, unit)	
	end
	end
	
	if(unit == "targettarget") or (unit=="focustarget") or (unit == "pet") then	
	self.Name:SetPoint("TOPLEFT", self, "TOPLEFT", 2, 0)
	self:Tag(self.Name, '[raidcolor][shortname]')
	
	hp:SetHeight(height.S)
	hp:SetWidth(width.S)	
	pp:SetHeight(4)
	pp:SetWidth(width.S*0.6)	
		
	self:SetAttribute('initial-height', height.S)
	self:SetAttribute('initial-width', width.S)		
	end	
	
	if(unit=="focustarget") or (unit == "pet") then		
		self.Debuffs = CreateFrame("Frame", nil, self)
		self.Debuffs.initialAnchor = "TOPLEFT"
		self.Debuffs.size = height.S		
		self.Debuffs['growth-x'] = 'RIGHT'	
		self.Debuffs:SetHeight(self.Debuffs.size)
		self.Debuffs:SetWidth(self.Debuffs.size*5)
		self.Debuffs.num = 5	
		self.Debuffs.spacing = 1
		self.Debuffs:SetPoint("TOPLEFT", hp, "TOPRIGHT", 4, 0)
	end
	
	if(unit=="targettarget") then		
		self.Debuffs = CreateFrame("Frame", nil, self)
		self.Debuffs.initialAnchor = "TOPRIGHT"
		self.Debuffs.size = height.S		
		self.Debuffs['growth-x'] = 'LEFT'	
		self.Debuffs:SetHeight(self.Debuffs.size)
		self.Debuffs:SetWidth(self.Debuffs.size*5)
		self.Debuffs.num = 5	
		self.Debuffs.spacing = 1
		self.Debuffs:SetPoint("TOPRIGHT", hp, "TOPLEFT", -4, 0)
	end	
	
    local MainT = self:GetParent():GetName()=="oUF_MainTank"
    local MainTar = strsub(self:GetName(), 24)=="Target"
    local MainToT = strsub(self:GetName(), 24)=="TargetTarget"
	
    if(MainT or MainTar or MainToT) then
	self.Name:SetPoint("LEFT", hp, "LEFT", 2, 0)
	self:Tag(self.Name, '[raidcolor][abbrevname]')
	self.Name:SetFont(NumbFont, NumbFS*0.9, FontF)
	self.Text:SetPoint("RIGHT", hp, "RIGHT", -2, 0)
	self.Text:SetFont(NumbFont, NumbFS, FontF)	
	self:Tag(self.Text, '[perhp]')	
	hp:SetHeight(height.M)
	hp:SetWidth(width.M)
	pp:Hide()	
	
	if MainT then
		self.Debuffs = CreateFrame("Frame", nil, self)
		self.Debuffs.initialAnchor = "TOPLEFT"
		self.Debuffs.size = height.M		
		self.Debuffs['growth-x'] = 'RIGHT'	
		self.Debuffs:SetHeight(self.Debuffs.size)
		self.Debuffs:SetWidth(self.Debuffs.size*3)
		self.Debuffs.num = 3	
		self.Debuffs.spacing = 1
		self.Debuffs:SetPoint("TOPLEFT", hp, "TOPRIGHT", 4, 0)
		self.PostCreateAuraIcon = auraIcon	
	end
	
	self:SetAttribute('initial-scale', MainTankScale)	
	self:SetAttribute('initial-height', height.M)
	self:SetAttribute('initial-width', width.M)		
    return self	
	end

	if(self:GetName():match"oUF_Arena") then
		self.Name:SetPoint("TOPLEFT", hp, "TOPLEFT", 2, -2)
		self:Tag(self.Name, '[raidcolor][raidhpname]')
		self.Text:SetPoint("TOPRIGHT", hp, "TOPRIGHT", -2, -2)			
		self.Name:SetFont(NumbFont, NumbFS*0.9, FontF)
		self.Text:SetFont(NumbFont, NumbFS*0.9, FontF)	
		
		hp:SetHeight(height.M)
		hp:SetWidth(width.M)	
		pp:SetHeight(4)
		pp:SetWidth(width.M*0.6)
		pp:SetPoint("BOTTOMRIGHT", hp, "BOTTOMRIGHT", -2, 0)
		
		self.Buffs = CreateFrame("Frame", nil, self)
		self.Buffs.initialAnchor = "TOPLEFT"
		self.Buffs.size = myBuffSize	
		self.Buffs['growth-x'] = 'RIGHT'	
		self.Buffs:SetHeight(self.Buffs.size)
		self.Buffs:SetWidth(self.Buffs.size*10)
		self.Buffs.num = 9
		self.Buffs.spacing = 0		
		self.Buffs.onlyShowPlayer = true
		self.Buffs:SetPoint("TOPLEFT", self, "TOPRIGHT", height.M+4, 0)

		self.Debuffs = CreateFrame("Frame", nil, self)
		self.Debuffs.initialAnchor = "TOPRIGHT"
		self.Debuffs.size = myDebuffSize		
		self.Debuffs['growth-x'] = 'LEFT'	
		self.Debuffs:SetHeight(self.Debuffs.size)
		self.Debuffs:SetWidth(self.Debuffs.size*4)
		self.Debuffs.num = 3	
		self.Debuffs.spacing = 1
		self.Debuffs:SetPoint("TOPRIGHT", hp, "TOPLEFT", -4, 0)
	
	self:SetAttribute('initial-scale', ArenaScale)		
	self:SetAttribute('initial-height', height.M)
	self:SetAttribute('initial-width', width.M)	
	end
	
	if(unit and unit:find("arena%dtarget")) then	
	hp:SetHeight(height.M)
	hp:SetWidth(32)
	pp:SetWidth(32*0.6)	
	self.Buffs:ClearAllPoints()
	self.Debuffs:ClearAllPoints()
	self.Name:ClearAllPoints()
	self.Name:SetPoint("BOTTOM", self, "TOP", 0, 2)
	self:Tag(self.Name, '[raidcolor][shortname]')
	self:SetAttribute('initial-scale', ArenaScale)	
	self:SetAttribute('initial-height', height.M)
	self:SetAttribute('initial-width', 32)			
	end
	
	if(unit:match("boss%d")) then
	self.Name:SetPoint("LEFT", hp, "LEFT", 2, 0)
	self:Tag(self.Name, '[raidcolor][abbrevname]')
	self.Name:SetFont(NumbFont, NumbFS*0.9, FontF)
	self.Text:SetPoint("RIGHT", hp, "RIGHT", -2, 0)
	self.Text:SetFont(NumbFont, NumbFS, FontF)	
	self:Tag(self.Text, '[perhp]')	
	hp:SetHeight(height.M)
	hp:SetWidth(width.M)
	pp:Hide()
	
	self:SetAttribute('initial-scale', MainTankScale)	
	self:SetAttribute('initial-height', height.M)
	self:SetAttribute('initial-width', width.M)	
	end
	
	-- scale teh sh..
	if(unit == "player") or (unit == "pet") then
	self:SetAttribute('initial-scale', PlayerScale)
	elseif(unit == "target") or (unit == "targettarget") then
	self:SetAttribute('initial-scale', TargetScale)
	elseif(unit == "focus") or (unit == "focustarget")  then
	self:SetAttribute('initial-scale', FocusScale)
	end
	
	self.PostUpdateHealth = updateHealth
	self.PostUpdatePower = updatePower

	self.PostCreateAuraIcon = auraIcon
	self.PostUpdateAuraIcon = auraUpdateIcon
	self.PostUpdateAura = auraUpdate
	
	if(unit and unit ~= "target") then	
		self:RegisterEvent("UNIT_THREAT_LIST_UPDATE", updateThreatStatus)
		self:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", updateThreatStatus)
	end
		self:RegisterEvent("UNIT_AURA", updateDispel)	
	return self 	
end

-- spawn them ...
oUF:RegisterStyle("oUF_viv5_solo", Shared)
oUF:SetActiveStyle"oUF_viv5_solo"

oUF:Spawn("player", "oUF_Player"):SetPoint("BOTTOM", -160, 190)
oUF:Spawn("pet", "oUF_Pet"):SetPoint("TOPLEFT", oUF_Player, "BOTTOMLEFT", 0, -6)

oUF:Spawn("target", "oUF_Target"):SetPoint("BOTTOM", UIParent, 160, 190)
oUF:Spawn("focus", "oUF_Focus"):SetPoint("TOPLEFT", oUF_Target, "TOPRIGHT", 60, 0)

oUF:Spawn("targettarget", "oUF_TargetTarget"):SetPoint("TOPRIGHT", oUF_Target, "BOTTOMRIGHT", 0, -6)
oUF:Spawn("focustarget", "oUF_FocusTarget"):SetPoint("TOPLEFT", oUF_Focus, "BOTTOMLEFT", 0, -6)

if useArenaFrames == true then
local arena = {}
for i = 1, 5 do
	arena[i] = oUF:Spawn("arena"..i, "oUF_Arena"..i)
	if i == 1 then
		arena[i]:SetPoint("BOTTOMLEFT", oUF_Focus, "TOPLEFT", 0, 280)
	else
		arena[i]:SetPoint("TOP", arena[i-1], "BOTTOM", 0, -20)
	end
end

local arenatarget = {}
	for i = 1, 5 do
		arenatarget[i] = oUF:Spawn("arena"..i.."target", "oUF_Arena"..i.."target")
		if i == 1 then
			arenatarget[i]:SetPoint("TOPLEFT", arena[i], "TOPRIGHT", 6, 0)
		else
			arenatarget[i]:SetPoint("TOP", arenatarget[i-1], "BOTTOM", 0, -20)
		end
	end
end

if usemaintank == true then
local main_tank = oUF:Spawn("header", "oUF_MainTank")
main_tank:SetManyAttributes("showRaid", true, "groupFilter", "MAINTANK", "yOffset", -12)
main_tank:SetPoint("TOP", UIParent, "TOP", 540, -280)
main_tank:SetAttribute("template", "oUF_vivMTartemplate")	-- MainTank Target
--main_tank:SetAttribute("template", "oUF_vivMToTtemplate")	-- MainTank ToT
main_tank:Show()
end

if usebossframes == true then
local boss = {}
for i = 1, MAX_BOSS_FRAMES do
	boss[i] = oUF:Spawn("boss"..i, "oUF_Boss"..i)

	if i == 1 then
		boss[i]:SetPoint("TOP", oUF_MainTank, "BOTTOM", 0, -80)
	else
		boss[i]:SetPoint("TOP", boss[i-1], "BOTTOM", 0, -12)
	end
end
for i, v in ipairs(boss) do v:Show() end 
end


-- background frames
if useviewport == true then
	local bottompan = CreateFrame("Frame",nil,UIParent)
	bottompan:SetFrameStrata("BACKGROUND")
	bottompan:SetFrameLevel(3)	
	bottompan:SetWidth(1366)
	bottompan:SetHeight(viewportTextureBottomValue)
	bottompan:SetPoint("BOTTOMLEFT", 0, 0)
	bottompan:Show()
	bottompan:SetScale(panelscale)
	local bottompan2 = bottompan:CreateTexture(nil,"BACKGROUND")
	bottompan2:SetTexture(BottomPanelTex)
	bottompan2:SetAllPoints(bottompan)	
	bottompan2:SetVertexColor(maincolor[1],maincolor[2],maincolor[3])
	--bottompan2:SetVertexColor(sndcolor[1], sndcolor[2], sndcolor[3]) 	
	bottompan2:SetAlpha(1)
	
	bottompan.overlay = bottompan:CreateTexture(nil, "OVERLAY")
	bottompan.overlay:SetTexture(BottomPanelOvTex)
	bottompan.overlay:SetWidth(1366)
	bottompan.overlay:SetHeight(1.5)		
	bottompan.overlay:SetPoint("BOTTOM", bottompan, "TOP", 0, 0)	
	bottompan.overlay:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])	
	bottompan.overlay:SetAlpha(0.5)
	
	local BPanel = CreateFrame("Frame",nil,UIParent)
	BPanel:SetFrameStrata("BACKGROUND")
	BPanel:SetFrameLevel(3)	
	BPanel:SetWidth(1366)
	BPanel:SetHeight(14)
	BPanel:SetPoint("BOTTOM", bottompan, "TOP", 0, 0)
	BPanel:Show()
	BPanel:SetScale(panelscale)
	local BPanel2 = BPanel:CreateTexture(nil,"BACKGROUND")
	BPanel2:SetTexture(BottomPanelTex)
	BPanel2:SetAllPoints(BPanel)	
	--BPanel2:SetVertexColor(maincolor[1],maincolor[2],maincolor[3])
	BPanel2:SetVertexColor(sndcolor[1], sndcolor[2], sndcolor[3]) 	
	BPanel2:SetAlpha(0.3)	
	
	BPanel.overlay = BPanel:CreateTexture(nil, "OVERLAY")
	BPanel.overlay:SetTexture(BottomPanelOvTex)
	BPanel.overlay:SetWidth(1366)
	BPanel.overlay:SetHeight(1)		
	BPanel.overlay:SetPoint("BOTTOM", BPanel, "TOP", 0, 0)	
	BPanel.overlay:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])	
	BPanel.overlay:SetAlpha(0.5)	
	
	local toppan = CreateFrame("Frame",nil,UIParent)
	toppan:SetFrameStrata("BACKGROUND")
	toppan:SetFrameLevel(3)		
	toppan:SetWidth(1366)
	toppan:SetHeight(viewportTextureTopValue)
	toppan:SetPoint("TOPLEFT", 0, 0)
	toppan:Show()
	toppan:SetScale(panelscale)
	local toppan2 = toppan:CreateTexture(nil,"BACKGROUND")
	toppan2:SetTexture(TopPanelTex)
	toppan2:SetAllPoints(toppan)	
	toppan2:SetVertexColor(maincolor[1],maincolor[2],maincolor[3])
	--toppan2:SetVertexColor(sndcolor[1], sndcolor[2], sndcolor[3]) 	
	toppan2:SetAlpha(1)	

	toppan.overlay = toppan:CreateTexture(nil, "OVERLAY");
	toppan.overlay:SetTexture(TopPanelOvTex);
	toppan.overlay:SetWidth(1366)
	toppan.overlay:SetHeight(1.5)	
	toppan.overlay:SetPoint("TOP", toppan, "BOTTOM", 0, 0)
	toppan.overlay:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])
	toppan.overlay:SetAlpha(0.5)
	
	local TPanel = CreateFrame("Frame",nil,UIParent)
	TPanel:SetFrameStrata("BACKGROUND")
	TPanel:SetFrameLevel(3)	
	TPanel:SetWidth(1366)
	TPanel:SetHeight(14)
	TPanel:SetPoint("TOP", toppan, "BOTTOM", 0, 0)
	TPanel:Show()
	TPanel:SetScale(panelscale)
	local TPanel2 = TPanel:CreateTexture(nil,"BACKGROUND")
	TPanel2:SetTexture(BottomPanelTex)
	TPanel2:SetAllPoints(TPanel)	
	--TPanel2:SetVertexColor(maincolor[1],maincolor[2],maincolor[3])
	TPanel2:SetVertexColor(sndcolor[1], sndcolor[2], sndcolor[3]) 	
	TPanel2:SetAlpha(0.3)	
	
	TPanel.overlay = TPanel:CreateTexture(nil, "OVERLAY")
	TPanel.overlay:SetTexture(BottomPanelOvTex)
	TPanel.overlay:SetWidth(1366)
	TPanel.overlay:SetHeight(1)		
	TPanel.overlay:SetPoint("TOP", TPanel, "BOTTOM", 0, 0)	
	TPanel.overlay:SetVertexColor(trdcolor[1], trdcolor[2], trdcolor[3])	
	TPanel.overlay:SetAlpha(0.5)		
	
-- modify the worldframe (create a viewport)
local top = viewportTopValue
local bottom = viewportBOTTOMValue
local left = 0
local right = 0
local currentYResolution = 1050

local scaling = 768 / 1050
	
ViewportOverlay = WorldFrame:CreateTexture(nil, "BACKGROUND")
ViewportOverlay:SetTexture(0, 0, 0, 1)
ViewportOverlay:SetPoint("TOPLEFT", UIParent, "TOPLEFT", -1, 1)
ViewportOverlay:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", 1, -1)

WorldFrame:SetPoint("TOPLEFT", (left * scaling), -(top * scaling))
WorldFrame:SetPoint("BOTTOMRIGHT", -(right * scaling), (bottom * scaling))
WorldFrame:SetPoint("TOPLEFT", 0, -(top * 0.75))
WorldFrame:SetPoint("BOTTOMRIGHT", 0, (bottom * 0.75))
end